/***************************************************************************
 *   Copyright (C) 2008 by BogDan Vatra                                    *
 *   bogdan@licentia.eu                                                    *
 *                                                                         *
 *   This program is free software: you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 ***************************************************************************/

#ifndef TEXTEDIT_H
#define TEXTEDIT_H

#include <QMainWindow>
#include <QMap>
#include <QPointer>
#include "win32def.h"

class QAction;
class QComboBox;
class QFontComboBox;
class QTextEdit;
class QTextCharFormat;
class QHBoxLayout;
class QVBoxLayout;

class KONTAMABIL_EXPORTS TextEditToolBar : public QWidget
{
	Q_OBJECT
	Q_PROPERTY(QString textEditName READ textEditName WRITE setTextEditName)

public:
	TextEditToolBar(QWidget *parent = 0);

	QString textEditName();
	void setTextEditName(const QString & textEditName);

protected:
	void showEvent ( QShowEvent * event );

private:
	void setupEditActions();
	void setupTextActions();

private slots:

	void textBold();
	void textUnderline();
	void textItalic();
	void textFamily(const QString &f);
	void textSize(const QString &p);
	void textStyle(int styleIndex);
	void textColor();
	void textAlign(QAction *a);

	void currentCharFormatChanged(const QTextCharFormat &format);
	void cursorPositionChanged();

	void clipboardDataChanged();

private:
	void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
	void fontChanged(const QFont &f);
	void colorChanged(const QColor &c);
	void alignmentChanged(Qt::Alignment a);

	QAction *m_actionTextBold,
	*m_actionTextUnderline,
	*m_actionTextItalic,
	*m_actionTextColor,
	*m_actionAlignLeft,
	*m_actionAlignCenter,
	*m_actionAlignRight,
	*m_actionAlignJustify,
	*m_actionUndo,
	*m_actionRedo,
	*m_actionCut,
	*m_actionCopy,
	*m_actionPaste;

	QComboBox *m_comboStyle;
	QFontComboBox *m_comboFont;
	QComboBox *m_comboSize;

	QTextEdit *m_textEdit;
	QString m_textEditName;
	QHBoxLayout *m_horizontalLayout;
	QVBoxLayout *m_verticalLayout;
};

#endif
